package com.zhuhjay.service.imchat.model.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zhuhjay.common.base.constant.TimeConstant;
import com.zhuhjay.common.base.util.BeanBuilder;
import com.zhuhjay.service.imchat.model.entity.ChatMessage;
import com.zhuhjay.service.system.model.vo.ChatUserOnlineVo;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * @author ZhuHJay
 * @date 2023/11/12 10:59
 */
@Data
public class ChatMessageVo implements Serializable {

    private Long id;
    private Integer userId;
    private Integer roomId;
    private String content;
    private Long replyId;
    private Integer gapCount;
    @JsonFormat(pattern = TimeConstant.DATE_TIME_FORMAT_UTC, timezone = "GMT+8")
    private Date sendTime;
    private ChatUserOnlineVo userInfo;

    public static ChatMessageVo toVo(ChatMessage message) {
        return BeanBuilder.builder(ChatMessageVo::new)
                .with(ChatMessageVo::setId, message.getId())
                .with(ChatMessageVo::setUserId, message.getUserId())
                .with(ChatMessageVo::setRoomId, message.getRoomId())
                .with(ChatMessageVo::setContent, message.getContent())
                .with(ChatMessageVo::setReplyId, message.getReplyId())
                .with(ChatMessageVo::setGapCount, message.getGapCount())
                .with(ChatMessageVo::setSendTime, message.getCreateTime())
                .build();
    }

}
